package com.example.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Slf4j
public class TimeAspect {

    @Around("execution(* com.example.service.*.*(..))") //切入点表达式
    public Object rescordTime(ProceedingJoinPoint joinPoint) throws Throwable {
        //1.记录开始时间
        long begin = System.currentTimeMillis(); //通知
        //2.调用原始方法运行
        Object result = joinPoint.proceed();
        //3.记录结束时间，计算方法耗时
        long end = System.currentTimeMillis();//通知
        log.info(joinPoint.getSignature()+"方法执行时间：{}ms",end-begin);//通知
        return result;
    }
}
